home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Views / Includes / UTearOffMenuView.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  5.7 KB  |  196 lines  |  [TEXT/MPS ]

  1. // UTearOffMenuView.h
  2. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __UTEAROFFMENUVIEW__
  5. #define __UTEAROFFMENUVIEW__
  6.  
  7. // MacApp
  8.  
  9. #ifndef __UCOMMAND__
  10. #include "UCommand.h"
  11. #endif
  12.  
  13. #ifndef __UTRACKER__
  14. #include "UTracker.h"
  15. #endif
  16.  
  17. #ifndef __UMENUVIEW__
  18. #include "UMenuView.h"
  19. #endif
  20.  
  21. // Toolbox
  22.  
  23. //----------------------------------------------------------------------------------------
  24. // Forward and external class declarations. 
  25. //----------------------------------------------------------------------------------------
  26.  
  27. class TTearOffMenuView;
  28. class TWindow;
  29.  
  30.  
  31. //----------------------------------------------------------------------------------------
  32. // Constants
  33. //----------------------------------------------------------------------------------------
  34.  
  35. const short kTearOffMargin = 10;                // the slop around the displayed menu
  36.                                                 // within which we don't tear-off; see
  37.                                                 // Apple Human Interface Guidelines p. 91;
  38.                                                 // note: some programs (eg. HyperCard) use
  39.                                                 // a 15 pixel slop value 
  40.  
  41. const short kTearOffOffset = 3;                    // pixel offset from pointer to gray rgn
  42.                                                 // being dragged around 
  43.  
  44.  
  45. //----------------------------------------------------------------------------------------
  46. // TShowTearOffWindowCommand: moves, shows and selects a TTearOffMenuView 
  47. //----------------------------------------------------------------------------------------
  48.  
  49. class TShowTearOffWindowCommand : public TCommand
  50. {
  51.     MA_DECLARE_CLASS;
  52.     
  53. public:
  54.     TWindow* fTearOffWindow;
  55.  
  56.     CPoint fWhere;
  57.  
  58.  
  59.     TShowTearOffWindowCommand();
  60.         // Constructor
  61.     virtual ~TShowTearOffWindowCommand();
  62.         // Destructor
  63.         
  64.     void IShowTearOffWindowCommand(TWindow* tearOffWindow, CPoint where);
  65.  
  66.     virtual void DoIt();
  67.  
  68. };
  69.  
  70.  
  71. //----------------------------------------------------------------------------------------
  72. // TTearOffTracker: abstract superclass which provides the ability to process a tracking
  73. // command immediately rather than posting it to the queue.
  74. //----------------------------------------------------------------------------------------
  75.  
  76. class TTearOffMenuViewTracker : public TTracker
  77. {
  78.     MA_DECLARE_CLASS;
  79.     
  80. public:
  81.  
  82.     TTearOffMenuViewTracker();
  83.         // Empty constructor to satisfy compiler.
  84.     virtual ~TTearOffMenuViewTracker();
  85.         // Destructor
  86.         
  87.     void ITearOffMenuViewTracker(CommandNumber itsCommandNumber,
  88.                                  TCommandHandler* itsContext,
  89.                                  Boolean canUndo,
  90.                                  Boolean causesChange,
  91.                                  TObject* objectToNotify,
  92.                                   TView* itsView,
  93.                                  TScroller* itsScroller,
  94.                                  const VPoint& itsMouse);
  95.  
  96.     virtual Boolean IsReadyToPost();    // override
  97.         // Process the command immediately rather than posting to the command queue.
  98. };
  99.  
  100. //----------------------------------------------------------------------------------------
  101. // TTearOffTracker: abstract superclass providing basic tear-off menu tracking: tracks the
  102. // grey outline of the menu around the screen 
  103. //----------------------------------------------------------------------------------------
  104.  
  105. class TTearOffTracker : public TTearOffMenuViewTracker
  106. {
  107.     MA_DECLARE_CLASS;
  108.     
  109. public:
  110.     TTearOffMenuView* fTearOffMenu;
  111.  
  112.     RgnHandle fTearOffWindowOutline;
  113.  
  114.     Boolean fExitTracking;
  115.  
  116.     CPoint fOrigin;
  117.  
  118.     TTearOffTracker();
  119.         // Constructor
  120.         
  121.     void ITearOffTracker(CPoint hitPt, TTearOffMenuView* tearOffMenu);
  122.  
  123.     virtual ~TTearOffTracker();
  124.  
  125.     virtual void DoIt();
  126.  
  127.     virtual void TrackFeedback(TrackPhase aTrackPhase,
  128.                                         const VPoint& anchorPoint,
  129.                                         const VPoint& previousPoint,
  130.                                         const VPoint& nextPoint,
  131.                                         Boolean mouseDidMove,
  132.                                         Boolean turnItOn);
  133.  
  134.     virtual TTracker* TrackMouse(TrackPhase aTrackPhase,
  135.                                         VPoint& anchorPoint,
  136.                                         VPoint& previousPoint,
  137.                                         VPoint& nextPoint,
  138.                                         Boolean mouseDidMove);
  139.  
  140.     virtual Boolean IsDoneTracking();
  141.  
  142. };
  143.  
  144.  
  145. //----------------------------------------------------------------------------------------
  146. // TTearOffMenuView: abstract superclass providing basic tear-off menu behavior 
  147. //----------------------------------------------------------------------------------------
  148.  
  149. class TTearOffMenuView : public TMenuView
  150. {
  151.     MA_DECLARE_CLASS;
  152.     
  153. public:
  154.     RgnHandle fTearOffTrackingRegion;
  155.  
  156.     TTearOffTracker* fTearOffTracker;
  157.  
  158.     TWindow* fTearOffWindow;
  159.  
  160.     TTearOffMenuView();
  161.         // Constructor
  162.         
  163.     void ITearOffMenuView(ResNumber rsrcID,
  164.                                          short menuWidth,
  165.                                          short menuHeight,
  166.                                          TWindow* tearOffWindow);
  167.  
  168.     virtual void InstallTearOffTracker();
  169.         // For the sake of efficiency when tracking a tear-off, we'll create the tear-off
  170.         // tracker and keep it with us, so we don't need to allocate a new tracker every
  171.         // time we tear off a menu. If you want a different tracker in your subclass of
  172.         // TTearOffMenuView, then override this method. 
  173.  
  174.     virtual ~TTearOffMenuView();
  175.  
  176.     virtual void HandleChooseMessage(short message,
  177.                                             MenuRef theMenu,
  178.                                             CRect& menuRect,
  179.                                             CPoint hitPt,
  180.                                             short& whichItem);
  181.         // initiates tracking if mouse is in fTearOffTrackingRegion 
  182.  
  183.     virtual RgnHandle GetTearOffTrackingRegion(const CRect& menuRect);
  184.         // accessor for fTearOffTrackingRegion: a rgn that represents the desktop less the
  185.         // menu CRect (with some buffer area around the menu CRect). This is useful for
  186.         // testing whether tracking should occur because the mouse just might be in the
  187.         // menu bar (which isn't in the desktop & isn't in the menu CRect) and so tracking
  188.         // should not occur while the mouse is in the menu bar (MenuSelect does that
  189.         // tracking just fine). 
  190.  
  191. };
  192.  
  193.  
  194. #endif
  195.  
  196.